package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.entity.player.ReturnData;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2022/3/22 16:47
 */
@Cmd(code = GameProtocol.S_WING_ROOM_FURNITURE_RECYCLE, desc = "家具回收")
public class RecycleFurnitureCmd extends AbstractCommand {
    private List<WingRoomProto.RecycleFurnitureTempMsg> recycleFurnitureList;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.RecycleFurnitureReqMsg reqMsg = WingRoomProto.RecycleFurnitureReqMsg.parseFrom(packet.getBytes());
        recycleFurnitureList = reqMsg.getRecycleFurnitureList();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        WingRoomProto.RecycleFurnitureRespMsg.Builder respMsg = WingRoomProto.RecycleFurnitureRespMsg.newBuilder();
        ReturnData returnData = player.getModule(WingRoomModule.class).recycleFurniture(recycleFurnitureList);
        respMsg.setRet(returnData.getRet());
        if (returnData.getRet() != 0) {
            player.sendPacket(ClientProtocol.U_WING_ROOM_FURNITURE_RECYCLE, respMsg);
            return;
        }
        respMsg.setReward(returnData.getParams().get(0));
        player.sendPacket(ClientProtocol.U_WING_ROOM_FURNITURE_RECYCLE, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
